﻿@model List<iChip.Hotspots.Models.HotspotsObject>
@{
    ViewBag.Title = "Danh sách Hotspots";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div id="addHotspots" class="modal fade" tabindex="-1" data-width="400">
    <div class="modal-dialog">
        <div class="modal-content">
            @{Html.RenderAction("AddHotspots", "AdminHotspots");}           
        </div>
    </div>
</div>
<!-- /.modal -->
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<!-- BEGIN PAGE HEADER-->
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            Danh sách Hotspots
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="/">Home</a>
                <i class="icon-angle-right"></i>
            </li>
            <li><a href="#">Danh sách Hotspots</a></li>
            <li class="pull-right">
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<div class="row">
    <div class="col-md-12 col-sm-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet box grey">
            <div class="portlet-title">
                <div class="caption"><i class="icon-globe"></i>Danh sách Hotspots</div>
                <div class="actions">
                    <a class="btn blue" id="aAdd"><i class="icon-pencil"></i> Thêm Hotspot</a>                    
                </div>
            </div>
            <div class="portlet-body">
                @if(Model!=null && Model.Count>0)
                { 
                <table class="table table-striped table-bordered table-hover" id="tbHotspots">
                    <thead>
                        <tr>
                            <th style="width1:8px;">#</th>
                            <th>Tên Hotspots</th>                            
                            <th>Mac</th>
                            <th>Ip</th>
                            <th>Nasid</th>
                            <th>Trang Splash</th>
                            <th>Trạng thái</th>
                            <th>Tùy chọn</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach(var item in Model)
                        { 
                            <tr class="odd gradeX">
                                <td>@item.Hotspot_Id</td>
                                <td>@item.Hotspot_Name</td>
                                <td>@item.Hotspot_Mac</td>
                                <td>@item.Hotspot_Ip</td>
                                <td>@item.Hotspot_Nasid</td>                                
                                <td><a href="@Url.Action("index", "AdminSplashs", new { Hotspot_id = @item.Hotspot_Id, Hotspot_mac = @item.Hotspot_Mac})"><span class="label label-sm label-default">Splash</span></a></td>                                                                
                                <td>
                                    @if (item.Hotspot_Status)
                                    {
                                        <span class="label label-sm label-success">Approved</span>
                                    }
                                    else
                                    {
                                        <span class="label label-sm label-warning">No Approved</span>
                                    }
                                </td>                                                                
                                <td><a name="aEdit" data-url="@Url.Action("AddHotspots","AdminHotspots")" data-id="@item.Hotspot_Id" class="btn default btn-xs purple"><i class="icon-edit"></i> Sửa</a>&nbsp;<a href="#" class="btn default btn-xs black"><i class="icon-trash"></i> Xóa</a></td>
                            </tr>
                        }                        
                    </tbody>
                </table>
                }
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>    
</div>

@section Scripts {
    <script>
    $('#btAddHotspot').click(function (e) {
        e.preventDefault();
        $.ajax({
            url: '@Url.Action("AddHotspots","AdminHotspots")', //this is the submit URL
                type: 'POST', //or POST
                data: $('#formaddHotspots').serialize(),
                success: function (data) {
                    if (data.Status == true) {
                        window.location.reload();
                    }
                    else {
                        $("#lblNote").addClass("red").text(data.Message);
                    }
                }
            });
        });       

        $("[name=aEdit]").click(function (e) {
            e.preventDefault();
            var url = $(this).data("url") + "?Hotspot_id=" + $(this).data("id");
            console.log($(this), $(this).data("id"), $(this).data("url"), url);
            $.get(url, function (data) {
                $('#addHotspots div.modal-content').html(data);
                $('#addHotspots').modal('show');
                App.init(); // initlayout and core plugins

                $('#btEditHotspot').click(function (e) {
                    e.preventDefault();                    
                    $.ajax({
                        url: '@Url.Action("AddHotspots","AdminHotspots")', //this is the submit URL
                        type: 'POST', //or POST
                        data: $('#formaddHotspots').serialize(),
                        success: function (data) {
                            if (data.Status == true) {
                                window.location.reload();
                            }
                            else {
                                $("#lblNote").addClass("red").text(data.Message);
                            }
                        }
                    });
                });
            });
        });

        $("#aAdd").click(function (e) {
            e.preventDefault();
            $.get('@Url.Action("AddHotspots", "AdminHotspots")', function (data) {
            $('#addHotspots div.modal-content').html(data);
            $('#addHotspots').modal('show');
            App.init(); // initlayout and core plugins
        });
    });
    </script>
}
